#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_log.h"


// 创建一个信号量
SemaphoreHandle_t bin_sem;

void taskA(void* param){
    // 释放信号量
    while(1){
        xSemaphoreGive(bin_sem);
        vTaskDelay(pdMS_TO_TICKS(1000));
    }

}

void taskB(void* param){
    // 等待信号量成功后，打印提示
    while(1){
        if (pdTRUE == xSemaphoreTake(bin_sem, portMAX_DELAY))
        {
            ESP_LOGI("bin", "task B take binsem success");
        }
    }
}

void app_main(void)
{
    // 创建信号量(互斥锁)
    bin_sem = xSemaphoreCreateBinary();
    // 创建任务A
    xTaskCreatePinnedToCore(taskA,"taskA",2048,NULL,3,NULL,1);
    xTaskCreatePinnedToCore(taskB,"taskB",2048,NULL,4,NULL,1);
}
